﻿using Skills;

using UnityEngine;
using XNode;

public class SkillNode : MyXNode
{
    [Input(backingValue = ShowBackingValue.Always)]
    public SkillNode[] unlockNodes;
    [Output]
    public SkillNode self;

    public Skill m_skill;
    [SerializeField]
    private bool unlock;
    public bool Unlock
    {
        get => unlock;
        private set
        {
            unlock = value;
        }
    }
    [SerializeField]
    private bool learned;
    public bool Learned
    {
        get => learned;
        set
        {
            learned = value;
            if (value)
                Unlock = true;
            UpdateUnlock();
        }
    }
    public int cost_sp;

    public string GetInformation()
    {
        string ret = TextTool.Wrap(m_skill.GetDescription(), 15).FontSize(14);
        ret += $"\n花费{cost_sp}SP".ColorText("red");
        return ret;
    }

    public override void Input()
    {
        base.Input();
        UpdateUnlock();
    }

    public void UpdateUnlock()
    {
        if (unlockNodes != null)
            foreach (SkillNode skill in unlockNodes)
            {
                skill.Unlock = Learned;
            }
    }

    public override object Output(NodePort port)
    {
        if (port.fieldName == nameof(self))
            return this;
        return base.Output(port);
    }
}